package com.japstudy.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.japstudy.entity.StarWord;
import com.japstudy.service.IStarWordService;

@Controller
@RequestMapping("StarWord")
public class StarWordController {

	@Autowired
	private IStarWordService starWordServiceImpl;
	
	@RequestMapping("add")
	public String add(StarWord starWord, HttpServletRequest request, HttpServletResponse response) throws IOException {
		int result = starWordServiceImpl.add(starWord);
		if(1 == result) {
			response.sendRedirect(request.getContextPath() + "/Word/userSelectAll");
		}
		return null;
	}
	
	@RequestMapping("delete")
	public String delete(StarWord starWord, HttpServletRequest request, HttpServletResponse response) throws IOException {
		int result = starWordServiceImpl.delete(starWord);
		if(1 == result) {
			response.sendRedirect(request.getContextPath() + "/Word/userSelectAll");
		}
		return null;
	}
	
	@RequestMapping("deleteOfStarPage")
	public String deleteOfStarPage(StarWord starWord, HttpServletRequest request, HttpServletResponse response) throws IOException {
		int result = starWordServiceImpl.delete(starWord);
		if(1 == result) {
			response.sendRedirect(request.getContextPath() + "/Word/userSelectAllStarWord");
		}
		return null;
	}
	
	@RequestMapping("selectAllByLoginUser")
	public @ResponseBody List<StarWord> selectAllByLoginUser(String loginUserId, HttpServletRequest request, HttpServletResponse response) throws IOException {
		List<StarWord> result = starWordServiceImpl.selectAllByLoginUser(loginUserId);
		return result;
	}
}
